package com.wzdigit.wms.wms.controller.outbound;


import com.wzdigit.framework.exception.RestStatusException;
import com.wzdigit.wms.basic.client.Pager;
import com.wzdigit.wms.basic.client.PagerInfo;
import com.wzdigit.wms.basic.client.Queryer;
import com.wzdigit.wms.basic.client.request.picktask.PicktaskMangementRequest;
import com.wzdigit.wms.basic.client.response.picktask.PicktaskMangementResp;
import com.wzdigit.wms.basic.domain.dtos.outbound.PicktaskDto;
import com.wzdigit.wms.basic.client.response.Result;
import com.wzdigit.wms.basic.client.response.picktask.PicktaskDtlInfoResp;
import com.wzdigit.wms.wms.constant.WmsWareConstant;
import com.wzdigit.wms.wms.service.outbound.PicktaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 拣货任务_PDA 前端控制器
 * </p>
 *
 * @author yangwenbiao
 * @since 2021-02-26
 */

@Slf4j
@RestController
@RequestMapping(value = WmsWareConstant.API_VERSION)
@Api(tags = "拣货任务_PDA")
public class OrderPickJobController {

    public static final String REQUEST_MODEL = "/order_pick_job_pda";

    @Autowired
    PicktaskService picktaskService;


    @ApiOperation(value = "拣货任务:主档")
    @GetMapping(value = REQUEST_MODEL + "/main")
    public Result<List<PicktaskDto>> getMainInfo(@ApiParam("发货单号") @RequestParam(required = false) String filter,
                                                 HttpServletRequest servletRequest,
                                                 HttpServletResponse servletResponse) throws Exception {
        try {
            Result<List<PicktaskDto>> result = picktaskService.getMainInfo(filter,servletRequest, servletResponse);
            return result;
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "拣货任务:主档分页")
    @GetMapping(value = REQUEST_MODEL + "/main/pageInfo")
    public PagerInfo<List<PicktaskDto>> getMainPageInfo(Pager<?> page,
                                                        @ApiParam("发货单号") @RequestParam(required = false) String filter,
                                                        HttpServletRequest servletRequest,
                                                        HttpServletResponse servletResponse) throws Exception {
        try {
            Queryer<String> requestQueryer = new Queryer<>();
            requestQueryer.setPage(page);
            requestQueryer.setRequest(filter);

            PagerInfo<List<PicktaskDto>> pagerInfo = picktaskService.getMainPage(requestQueryer, servletRequest, servletResponse);
            return pagerInfo;
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }






    @ApiOperation(value = "拣货任务:详情")
    @GetMapping(value = REQUEST_MODEL + "/datials/{picktaskHeaderId}")
    public Result<PicktaskDtlInfoResp> getDetails(@ApiParam("拣货任务ID") @PathVariable(value = "picktaskHeaderId") Integer picktaskHeaderId,
                                                  HttpServletRequest servletRequest,
                                                  HttpServletResponse servletResponse) throws Exception {
        try {

            Result<PicktaskDtlInfoResp> result = picktaskService.getDetails(picktaskHeaderId, servletRequest);
            return result;
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

}
